package com.beans;

import com.classe.Danos;
import com.dao.DanosDAO;
import java.io.Serializable;
import java.util.ArrayList;
import org.primefaces.event.map.OverlaySelectEvent;
import org.primefaces.model.map.DefaultMapModel;
import org.primefaces.model.map.LatLng;
import org.primefaces.model.map.MapModel;
import org.primefaces.model.map.Marker;


public class DanosBean implements Serializable {

    private MapModel advancedModel;
    private Marker marker;
    

    public DanosBean() {

        advancedModel = new DefaultMapModel();

        ArrayList<Danos> lista = DanosDAO.listar("");
        String status = "";

        for (int i = 0; i < lista.size(); i++) {

            Danos danos = lista.get(i);

            if ("ANALISE".equals(danos.getStatus())) {
                status = "FFFF00";
            }
            else if  ("IMPROCEDENTE".equals(danos.getStatus())) {
                status = "00FF00";
            }
            else if ("PROCEDENTE".equals(danos.getStatus())) {
                status = "FF0000";
            }

            LatLng coord1 = new LatLng(Double.valueOf(danos.getLatitude()), Double.valueOf(danos.getLongitude()));
            advancedModel.addOverlay(new Marker(coord1, "DADOS: \r\nUC: "+ danos.getProcesso()+"\r\nSequência: "+danos.getAno(), null, "http://www.googlemapsmarkers.com/v1/" //+ danos.getAno() + "/" 
                    + status
                         ));
            status = "";
        }
    }

    public MapModel getAdvancedModel() {
        return advancedModel;
    }

    public void onMarkerSelect(OverlaySelectEvent event) {
        marker = (Marker) event.getOverlay();
    }

    public Marker getMarker() {
        return marker;
    }
}
